#pragma once

#include <base.h>

#define TASK_USTACK_SIZE 0x4000
#define TASK_KSTACK_SIZE 0x1000

#define TASK_STATE_INVALID 0
#define TASK_STATE_RUNNING 1
#define TASK_STATE_READY 2
#define TASK_STATE_SLEEPING 3
#define TASK_STATE_DYING 4
#define TASK_STATE_DEAD 5

#define TASK_FLAG_USER BIT(0)

typedef struct {
	uint64_t tid;
	uint32_t task_flags;
	uint32_t task_state;
	uint64_t last_tick;

	uint64_t kstack_base;
	uint64_t kstack_top;
	uint64_t ustack_base;
	uint64_t ustack_top;
	uint64_t task_stack_top;
} task_block_t;

task_block_t *task_create(void (*entry)(void), uint64_t *page_table, uint32_t flags);
task_block_t *task_create_idle();

void task_add_test_tasks();